package com.tvein.sanguo.controller.Game.system
{
	//flash
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	//pureMVC
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.fabrication.patterns.command.SimpleFabricationCommand;
	//custom
	import com.tvein.sanguo.common.CommonConstants;
	import com.tvein.sanguo.model.ServerProxy;
//
	public class ModuleInit extends SimpleFabricationCommand implements ICommand
	{
		private var serverData:ServerProxy;
		
		override public function execute(notification:INotification) : void
		{
			serverData = facade.retrieveProxy(ServerProxy.NAME) as ServerProxy;
			
			sendNotification(CommonConstants.SYSTEM_CONSOLE, ["-moduleLoad", "/SanGuo/shell/action/Action.swf"]);
			sendNotification(CommonConstants.SYSTEM_CONSOLE, ["-moduleLoad", "/SanGuo/shell/background/BackGround.swf"]);
			sendNotification(CommonConstants.SYSTEM_CONSOLE, ["-moduleLoad", "/SanGuo/shell/character/Character.swf"]);
			sendNotification(CommonConstants.SYSTEM_CONSOLE, ["-moduleLoad", "/SanGuo/shell/chat/Chat.swf"]);
			sendNotification(CommonConstants.SYSTEM_CONSOLE, ["-moduleLoad", "/SanGuo/shell/crowd/Crowd.swf"]);
			sendNotification(CommonConstants.SYSTEM_CONSOLE, ["-moduleLoad", "/SanGuo/shell/event/Event.swf"]);
			sendNotification(CommonConstants.SYSTEM_CONSOLE, ["-moduleLoad", "/SanGuo/shell/prompt/Prompt.swf"]);
			sendNotification(CommonConstants.SYSTEM_CONSOLE, ["-moduleLoad", "/SanGuo/shell/room/Room.swf"]);
			sendNotification(CommonConstants.SYSTEM_CONSOLE, ["-moduleLoad", "/SanGuo/shell/tool/Tool.swf"]);
			sendNotification(CommonConstants.SYSTEM_CONSOLE, ["-moduleLoad", "/SanGuo/shell/zone/Zone.swf"]);
			
			var checkTimer:Timer = new Timer(100);
			checkTimer.addEventListener(TimerEvent.TIMER, _gameStart);
			checkTimer.start();
		}
		
		//Custom
		private function _gameStart(evt:TimerEvent):void
		{
			if (int(serverData.swfNum) == 10)
			{
				evt.target.stop();
				evt.target.removeEventListener(TimerEvent.TIMER, _gameStart);
				
				sendNotification(CommonConstants.GAME_CONSOLE, ["-gameStart"]);
			}
		}
	}
}